<?php
/**
 * Created by PhpStorm.
 * User: lenove
 * Date: 2018/12/6
 * Time: 14:38
 */
include "../config.php";
include "../Status.php";
//首先,限制请求方式
if($_SERVER["REQUEST_METHOD"]=="POST"){
    if(isset($_REQUEST["uname"]) && isset($_REQUEST["upwd"])){
        $oname = $_REQUEST["uname"];
        $opwd = $_REQUEST["upwd"];
        //准备sql语句;
        $sql = "INSERT INTO userInfo(`uname`,`upwd`) VALUES(?,?);";
        //预处理sql语句;
        $stmt = $conn->prepare($sql);
        //绑定参数
        $stmt->bind_param("ss",$oname,$opwd);
        //执行sql语句;
        $stmt->execute();
        if($stmt->affected_rows >= 1){
            print_r(json_encode(Status::$register_success));
        } else {
            print_r(json_encode(Status::$register_failure));
        }
        $stmt->close();
        $conn->close();
    }else{
        print_r(json_encode(Status::$register_error));
    }
}else{
    print_r(json_encode(Status::$request_error));
    return;
}
